import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'function.dart';

class MonitorRecord extends StatelessWidget {
  MonitorRecord(this.pushrecord, this.mainColor);
  final List pushrecord;
  final Color mainColor;
  _buildRecord(Map record) {
    String reason;
    if (record['push_type'] == "offline") {
      reason = "离线";
    } else if (record['push_type'] == "exception") {
      reason = "异常";
    } else {
      reason = "其他";
    }
    reason += " " + record['delay_time'];
    return new ListTile(
      title: new Text(reason),
      subtitle: new Text(record['device_name']),
      trailing: new Text(convertTime(int.parse(record['start_time']))),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new CupertinoNavigationBar(
        actionsForegroundColor: Colors.white,
        backgroundColor: this.mainColor,
        middle: new Text(
          "异常记录",
          style: new TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.normal,
          ),
        ),

      ),
      body: new ListView.builder(
        itemCount: pushrecord.length,
        itemBuilder: (context, i) => _buildRecord(pushrecord[i]),
      ),
    );
  }
}
